package com.plian.system.config;

import com.plian.Tools.pagedata.PageData;
import com.plian.system.config.exception.MyRuntimeException;
import com.plian.system.dao.sys.timing.TimingDao;
import com.plian.system.quartz.QuartTask;
import com.plian.system.quartz.QuartzManager;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class TimingConfig implements CommandLineRunner {
    @Autowired
    TimingDao timingDao;
    @Autowired
    QuartzManager quartzManager;
    @Autowired
    QuartTask quartTask;
    @Override
    public void run(String... args) throws Exception {
        try {
            List<PageData> list = timingDao.list(new PageData());
            for (PageData pd : list) {
                String status = pd.getString("status");
                if ("1".equals(status)) {
                    String fun = pd.getString("fun");
                    String timingType = pd.getString("timingType");
                    String timingMonth = pd.getString("timingMonth");
                    String timingDay = pd.getString("timingDay");
                    String timingHour = pd.getString("timingHour");
                    String timmingMinutes = pd.getString("timmingMinutes");
                    quartTask.task(fun,timingType,timingMonth,timingDay,timingHour,timmingMinutes);
                }
            }
        } catch (Exception e) {
            log.error(ExceptionUtils.getFullStackTrace(e));
            throw new MyRuntimeException();
        }
    }
}
